using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;


[System.Serializable]
public class VN_Configuration 
{

    public static VN_Configuration activeConfig;

    public static string filePath => $"{FilePath.root}vnconfig.cfg";

    public const bool ENCRYPT = false;

    //General Settings
    public bool display_fullscreen = true;
    public string display_resolution = "1920 * 1080";
    public bool continueSkippinAfterChoice = false;
    public float dialogueTextSpeed = 1f;
    public float dialogueAutoReadSpeed = 1f;

    //Auto Settings
    public float musicVolume = 1f;
    public float sfxVolume = 1f;
    public float voiceVolume = 1f;
    public bool musicMute = false;
    public bool sfxMute = false;
    public bool voiceMute = false;

    //Other Settings
    public float historyLogScale = 1f;
    
    public void Load()
    {
        var ui = ConfigMenu.instance.ui;

        //Apply the general settings
        Screen.fullScreen = display_fullscreen;
        ConfigMenu.instance.SetDisplayToFullScreen(fullscreen: display_fullscreen);
        ui.SetButtonColors(ui.fullscreen, ui.windowed, display_fullscreen);

        //Set the screen Resolution
        int res_index = 0;
        for (int i = 0; i < ui.resolutions.options.Count; i++)
        {
            string resolution = ui.resolutions.options[i].text;
            if (resolution == display_resolution)
            {
                res_index = i;
                break;
            }
        }
        ui.resolutions.value = res_index;

        ui.SetButtonColors(ui.skippingContinue, ui.skppingStop, continueSkippinAfterChoice);

        ui.architectSpeed.value = dialogueTextSpeed;
        ui.autoReaderSpeed.value = dialogueAutoReadSpeed;

        ui.musicVolume.value = musicVolume;
        ui.sfxVolume.value = sfxVolume;
        ui.voiceVolume.value = voiceVolume;

        TextMeshProUGUI musicMuteBtnTxt = ui.musicMuteBtn.GetComponentInChildren<TextMeshProUGUI>();
        TextMeshProUGUI sfxMuteBtnTxt = ui.sfxMuteBtn.GetComponentInChildren<TextMeshProUGUI>();
        TextMeshProUGUI voicesMuteBtnTxt = ui.voicesMuteBtn.GetComponentInChildren<TextMeshProUGUI>();
        musicMuteBtnTxt.SetText(musicMute ? "Muted" : "Mute");
        sfxMuteBtnTxt.SetText(sfxMute ? "Muted" : "Mute");
        voicesMuteBtnTxt.SetText(voiceMute ? "Muted" : "Mute");
    }

    public void Save()
    {
        FileManager.Save(filePath, JsonUtility.ToJson(this),encrypt: ENCRYPT);
    }

}
